#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | www.openfoam.com
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
#     Copyright (C) 2017-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
#     etc/pkgconfigAdjust
#
# Description
#     Adjust pkgconfig information to use '${prefix} where possible instead of
#     directory paths. This makes it easier when relocating software.
#     Adjusts includedir=, libdir=, -I/... and -L/... entries.
#
#     The specified directory can be any of the following:
#         - base-dir
#         - base-dir/bin
#         - base-dir/lib
#         - base-dir/lib64
#         - base-dir/lib/pkgconfig
#         - base-dir/lib64/pkgconfig
#
#     This allows this type of shell command
#
#        etc/pkgconfigAdjust $(find platforms -type d -name pkgconfig)
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
# Run from third-party directory only
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
    echo "Error (${0##*/}) : current directory is not \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

usage: ${0##*/} [OPTION] [directory1 [... directoryN]]
options:
  -help

Adjust pkgconfig files after relocating third-party files.
Locates pkgconfig files under the lib/ or lib64/ directories and adjusts them
to use '${prefix}' instead of absolute directory paths where possible.

USAGE
    exit 1
}
#------------------------------------------------------------------------------

# Process options/arguments
while [ "$#" -gt 0 ]
do
    case "$1" in
    '') ;;      # Ignore empty
    -h | -help*) usage   ;;

    *)
        pkgconfigAdjust "$1"
        ;;
    esac
    shift
done

#------------------------------------------------------------------------------
